'''
输入: nums = [1,3,-1,-3,5,3,6,7], 和 k = 3
输出: [3,3,5,5,6,7]
解释:

  滑动窗口的位置                最大值
---------------               -----
[1  3  -1] -3  5  3  6  7       3
 1 [3  -1  -3] 5  3  6  7       3
 1  3 [-1  -3  5] 3  6  7       5
 1  3  -1 [-3  5  3] 6  7       5
 1  3  -1  -3 [5  3  6] 7       6
 1  3  -1  -3  5 [3  6  7]      7

输入不能为空
来源：力扣（LeetCode）
链接：https://leetcode-cn.com/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof
著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。

'''
#暴力查找
# def maxSlidingWindow(list_num,k):
#     length = len(list_num)
#     index = 0
#     res = []
#     if k>length:
#         return False
#     while index+k<=length:
#         res.append(max(list_num[index:(k+index)]))
#         index+=1
#     return res
# print(maxSlidingWindow([1,3,-1,-3,5,3,6,7,10],3))
# # print(max([1,3,-1,-3,5,3,6,7]))

#递归思想
# def maxSlidingWindow(nums,k,index,res=[]):
#     if (k+index)>=len(nums):
#         return res
#     elif len(nums)==0:
#         return res
#     else:
#         res.append(max(nums[index:index+k]))
#         index+=1
#         return maxSlidingWindow(nums,k,index,res)
# print(maxSlidingWindow([1,3,-1,-3,5,3,6,7,10],3,0,res=[]))

#使用python内置函数map
def mmm(x):
    return max(x)
def mapmax(nums,k):
    index = 0
    res = []
    for  index in range((len(nums)-k+1)):
       res.append(list(map(mmm,[nums[index:index+k]])))
    return res
res = mapmax([1,3,-1,-3,5,3,6,7,10],3)
print(res)

#双端队列使用队列的思想

def maxde(nums,k):
    index,res = 0,[]
    while index<len(nums)-k+1:
        res.append(nums[index])
        for i in range(1,k):
            if res[index]<nums[i+index]:
                res.pop(-1)
                res.append(nums[i+index])
        index+=1
    return res
res = maxde([1,3,-1,-3,5,3,6,7,10],3)
print(res)
